package com.prd.controller;


import com.prd.dto.SysMenuDTO;
import com.prd.service.SysMenuService;
import com.prd.util.JsonData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 * 菜单（权限）数据表 前端控制器
 * </p>
 *
 * @author lizhaoyi
 * @since 2024-01-09
 */
@RestController
@RequestMapping("/api/sysMenu")
@Api(tags = "菜单管理")
public class SysMenuController {

    @Autowired
    private SysMenuService sysMenuService;

    @ApiOperation("新增菜单")
    @PostMapping("add")
    public JsonData add(@Validated @RequestBody SysMenuDTO sysMenuDTO) {

        return sysMenuService.insertMenu(sysMenuDTO);
    }

    @ApiOperation("修改菜单")
    @PutMapping
    public JsonData edit(@Validated @RequestBody SysMenuDTO sysMenuDTO){

        return sysMenuService.updateMenu(sysMenuDTO);
    }

    @ApiOperation("删除菜单")
    @DeleteMapping("/{menuId}")
    public JsonData remove(@PathVariable("menuId") Long menuId) {

        return sysMenuService.deleteMenuById(menuId);
    }

    /**
     * 获取菜单列表
     */
    @ApiOperation("获取菜单列表")
    @PostMapping("/list")
    public JsonData list(SysMenuDTO sysMenuDTO) {

        return  sysMenuService.selectMenuList(sysMenuDTO);
    }

    @ApiOperation("根据菜单ID查询信息")
    @GetMapping(value = "/{menuId}")
    public JsonData getInfo(@PathVariable Long menuId){

        return sysMenuService.selectMenuById(menuId);
    }

    @ApiOperation("获取菜单下拉树列表")
    @PostMapping("/treeSelect")
    public JsonData treeSelect(SysMenuDTO sysMenuDTO){

        return sysMenuService.treeSelect(sysMenuDTO);
    }

    @ApiOperation("根据角色ID查询菜单树信息")
    @GetMapping(value = "/roleMenuTreeSelect/{roleId}")
    public JsonData selectMenuListByRoleId(@PathVariable("roleId") Long roleId) {

        return sysMenuService.selectMenuListByRoleId(roleId);
    }

}

